package ui;

import java.awt.EventQueue;

import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.text.MaskFormatter;

import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.text.ParseException;

public class AddCategoryWindow extends JFrame {
	private AddCategoryPresenter presenter;

	private JTextField titleField;
	private JLabel titleLabel, errorLabel;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					AddCategoryWindow window = new AddCategoryWindow(new MainWindow());
					window.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public AddCategoryWindow(MainWindow mw) {
		presenter = new AddCategoryPresenter(this);
		initialize();
		setLocationRelativeTo(mw);
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		setBounds(100, 100, 240, 203);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		getContentPane().setLayout(null);
			
		titleField = new JTextField();
		titleField.setDocument(new JTextFieldLimit(15));
		titleField.setBounds(73, 42, 86, 20);
		getContentPane().add(titleField);
		titleField.setColumns(10);
		
		JButton saveButton = new JButton("Save");
		saveButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				presenter.saveButtonClicked();
			}
		});
		saveButton.setBounds(70, 73, 89, 23);
		getContentPane().add(saveButton);
		
		JLabel lblTitle = new JLabel("Title:");
		lblTitle.setBounds(44, 45, 46, 14);
		getContentPane().add(lblTitle);
		
		titleLabel = new JLabel("Create New Category");
		titleLabel.setFont(new Font("Tahoma", Font.BOLD, 14));
		titleLabel.setBounds(34, 11, 168, 20);
		getContentPane().add(titleLabel);
		
		errorLabel = new JLabel("");
		errorLabel.setFont(new Font("Tahoma", Font.BOLD, 11));
		errorLabel.setBounds(45, 138, 192, 14);
		getContentPane().add(errorLabel);
	}
	
	public AddCategoryPresenter getPresenter() {
		return presenter;
	}
	
	public String getCategoryName(){
		String categoryName = titleField.getText();
		return categoryName;
	}
	
	public JTextField getTitleField() {
		return titleField;
	}
	
}
